package com.ls.juc;

import java.util.concurrent.CountDownLatch;

//6个同学陆续离开班长锁门
public class CountDownLatchDemo {

    //人没有走就锁门了
    public static void main0(String[] args) {
        for (int i = 1; i <= 6; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + " 离开了");
            }, String.valueOf(i)).start();

        }

        System.out.println("锁门");
    }

    public static void main(String[] args) throws InterruptedException {
        //设置减少的初始值
        CountDownLatch countDownLatch = new CountDownLatch(6);
        for (int i = 1; i <= 6; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + " 离开了");
                countDownLatch.countDown();
            }, String.valueOf(i)).start();

        }

        //阻塞.等待
        countDownLatch.await();

        System.out.println("锁门");
    }
}
